<%@page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@page import="java.util.List"%>
<%@page import="com.yaodian100.ec.member.entity.ViewWishList"%>
<%@page import="java.text.DateFormat"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@taglib uri="http://java.sun.com/jstl/core_rt" prefix="c-rt"%>
<%@page import="com.yaodian100.core.common.utils.ServerValue"%>
<c-rt:set var="frontContextPath" value='<%=ServerValue.getFrontContextPath()%>'/>
<html>
<head>
<link rel="stylesheet" href="/css/table_sorter.css" type="text/css" id="" media="print, projection, screen" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Language" content="zh-CN" />
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<script type="text/javascript" charset="UTF-8" src="/js/jquery.tablesorter.js"></script>
<script type="text/javascript" charset="UTF-8" src="/js/jquery.metadata.js"></script>
<script type="text/javascript" charset="UTF-8" src="/js/jquery.tablesorter.pager.js"></script>
<script language="javascript">
$().ready(function(){
	var deleteId;
	var restockId;
	
	$("#current_location").html('&nbsp;&gt;&nbsp;收藏盒&nbsp;-&nbsp;收藏商品');
	$("#pager").hide();
	$("#del_dialog").dialog({
		autoOpen: false,
		bgiframe: true,
		width:300,
		modal: true
	});
	
	$("#mdialog").dialog({
		bgiframe: true,
		autoOpen: false,
		height: 150,
		width:250,
		modal: true
	});

	$("#m2dialog").dialog({
		bgiframe: true,
		width:300,
		modal: true,
		autoOpen: false
	});

	$("#sReminDialog").dialog({
		bgiframe: true,
		width:300,
		modal: true,
		autoOpen: false
	});
	
	$("#rcReminDialog").dialog({
		bgiframe: true,
		width:300,
		modal: true,
		autoOpen: false
	});
	
	$("#m_myCollection").css("font-weight","bold");

	$(":a[id*=cel_]").click(function(){
		deleteId = $(this).attr("id").split("_")[1];
		$("#del_dialog").dialog('open');
	});

	$("#delete_commit").click(function(){
		$("#del_dialog").dialog('close');
		$.post("${frontContextPath}/member/myCollection/deleteWishList.do",{delIdList:deleteId},delcallback,"json");
		function delcallback(result){
			if(result=='success'){
				location.reload();
			}else{
				$("#dialog_msg").text('删除失败！');
				$("#mdialog").dialog('open');
			}
		}
	});

	$(":input[id*=cb_]").click(function(){
		if($(":input[id*=cb_]").size() == $(":input[id*=cb_][checked]").size()){
			$("#cbAll").attr('checked',true);
		}else{
			$("#cbAll").removeAttr('checked');
		}
	});

	$(":input[id=del_button]").click(function(){
		var isFirst = true;
		deleteId = "";
		$(":input[id*=cb_]").each(function(){
			var text = $(this).attr('id').split('_')[1];
			if($("#cb_"+text).attr('checked')==true){
				if(isFirst){
					deleteId = text;
					isFirst = false;
				}else{
					deleteId+= ","+text;
				}
			}
		});
		if(deleteId.length!=0){$("#del_dialog").dialog('open');}else{$("#m2dialog").dialog('open');}
	});

	function refreshPage(){
		if($("#pagenum").attr('value')!=""){
			var splitT = $("#pagenum").attr('value').split('/');
			$(":span[id*=pNum]").text($("#pagenum").attr('value'));
			$("#curPage").text(splitT[0]);
			$("#totalPage").text(splitT[1]);
			$(":a[id*=directP_]").css({"font-weight":"normal",'color' : '#369'});
			$("#directP_"+splitT[0]).css({"font-weight":"bold",'color' : '#000'});
		}
	}

	$(":a[id=nextP]").click(function(){
		$("#pager_next").click();
		refreshPage();
	});
	
	$(":a[id=preP]").click(function(){
		$("#pager_pre").click();
		refreshPage();
	});

	$("#delete_cancel").click(function(){
		$("#del_dialog").dialog('close');
	});
	
	$("#msg_ok").click(function(){
		$("#mdialog").dialog('close');
	});

	$("#m2_ok").click(function(){
		$("#m2dialog").dialog('close');
	});

	$("#sr_ok").click(function(){
		$("#sReminDialog").dialog('close');
	});

	$("#cbAll").click(function(){
		$(":input[id*=cb_]").attr('checked',$("#cbAll").attr('checked'));
	});

	$(":a[id*=directP_]").click(function(){
		var text = $(this).attr('id').split('_')[1];
		var curP = $("#pagenum").attr('value').split('/')[0];
		if(text>curP){
			for(var i=0; i<text-curP; i++){
				$("#pager_next").click();
			}
			refreshPage();
		}else if(text<curP){
			for(var i=0; i<curP-text; i++){
				$("#pager_pre").click();
			}
			refreshPage();
		}
	});
	$(":a[id*=arestock_]").click(function(){
		restockId = $(this).attr('id').split('_')[1];
		$.post("${frontContextPath}/member/myCollection/saveRestockRemind.do",{wishListId:restockId},arcallback,"json");
		function arcallback(result){
			if(result=='success'){
				$("#sReminDialog").dialog('open');
				$("#remindseted_"+restockId).show();
				$("#crestock_"+restockId).show();
				$("#arestock_"+restockId).hide();
			}else{
				$("#dialog_msg").text('设定失败！');
				$("#mdialog").dialog('open');
			}
		}
	});

	if(${productListSize}==0){
		$("#pTable_body").html('<tr><td height="30" colspan="6">目前没有收藏任何商品，快把喜欢的商品加入收藏盒吧！</td></tr>');
	}else{
		$("#pTable").tablesorter(); 
		$(":td[id*=pdel_]").each(function(){$(this).html("￥<del>"+$(this).text()+"</del>");});
		$(":td[id*=pok_]").each(function(){$(this).html("￥"+$(this).text());});
		$("#pTable").tablesorterPager({container: $("#pager")})
		refreshPage();
	}

	$(":a[id*=crestock_]").click(function(){
		deleteId = $(this).attr("id").split("_")[1];
		$("#rcReminDialog").dialog('open');
		document.activeElement.blur();
	});

	$("#rcr_ok").click(function(){
		$("#rcReminDialog").dialog('close');
		$.post("${frontContextPath}/member/myCollection/cancelRestockRemind.do",{wishListId:deleteId},cRemindcallback,"json");
		function cRemindcallback(result){
			if(result=='success'){
				$("#remindseted_"+deleteId).hide();
				$("#crestock_"+deleteId).hide();
				$("#arestock_"+deleteId).show();
			}else{
				$("#dialog_msg").text('取消失败！');
				$("#mdialog").dialog('open');
			}
		}
	});

	$("#rcr_cancel").click(function(){
		$("#rcReminDialog").dialog('close');
	});

	$("#pTable_body tr").hover(function() {
		$(this).attr('class','onhover');
		},function(){
		$(this).removeAttr('class');
	});
});
</script>
</head>
<body>
<%
@SuppressWarnings("unchecked")
List<ViewWishList> cList = (List)request.getAttribute("viewWishList");
ViewWishList vwList;
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
%>
  <div class="content mb-od">
    <h2>收藏盒</h2>
    <div class="mb-show">
      <ul class="mb-tab">
        <li class="mb-tab-f"><a href="${frontContextPath}/member/myCollection/toproductc.do">收藏商品(<b>${productListSize}</b>)</a></li>
        <li><a href="${frontContextPath}/member/myCollection/tocategoriesc.do">收藏分类(<b>${categoryListSize}</b>)</a></li>
      </ul>
       <div class="a-function"><a href="${frontContextPath}/shopping/cart.do" class="icon-car">查看购物车</a></div>
      <p class="icon-collection"><strong>关于收藏盒</strong>：遇到感兴趣的商品时，如果还没决定立即购买，或者商品暂时缺货，您可以先把它放入到收藏盒，以方便下次的查找与购买。</p>
      <div class="f-lt" style="margin-bottom:-2em;"><input type="submit" id="del_button" value="删除所选" /></div>
      <p class="bg-gy" align="right" >共<span id="showCounter">${productListSize}</span>笔： <span id="pNum"></span>
      	<c-rt:choose><c-rt:when test="${productListSize<=20}">
			<span class="a-no">&lt; 上一页</span> |  <span class="a-no">下一页 &gt;</span>
		</c-rt:when><c-rt:otherwise>
			<a href="javascript:;" class="a-togo" id="preP">上一页</a> | <a href="javascript:;" class="a-togo" id="nextP">下一页</a>
		</c-rt:otherwise></c-rt:choose>
      </p>

      <table id="pTable" class="tablesorter {sortlist: [[3,1]]} tb-2">
		<thead>
			<tr>
			<th width="12" class="{sorter: false}"><input type="checkbox" id="cbAll" /></th>
            <th width="75" class="{sorter: false}">&nbsp;</th>
            <th><span><a href="javascript:;">商品名称</a></span></th>
            <th width="70" ><span><a href="javascript:;">收藏日期</a></span></th>
            <th width="120">状态</th>
            <th width="70" class="{sorter: 'digit'}"><span><a href="javascript:;">单价</a></span></th>
            <th width="80" class="{sorter: false}">操作</th>
			</tr>
			</thead>
        <tbody id="pTable_body">
        <% for(int i = 0 ; i < cList.size() ; i++){
        	vwList = cList.get(i);
        %>
          <tr id="vw_<%=vwList.getId() %>">
            <td><input type="checkbox" id="cb_<%=vwList.getId() %>" /></td>
            <td><a target=_blank href="<%=vwList.getFullUrl() %>"><img src="/PImg/<%=vwList.getProductId().substring(0,4) %>/<%=vwList.getProductId()%>/<%=vwList.getProductId()%>_m75.jpg" alt="" width="75" height="75"  onError="this.src='/PImg/blank_75.gif'" /></a></td>
            <td><p><a target=_blank href="<%=vwList.getFullUrl() %>"><%=vwList.getProductName()%></a></p></td>
            <td><%=dateFormat.format(vwList.getCreateDate())%></td>
            <td>
            <%if(vwList.getShelf_qty()!=0){%>出售中<%}else{%>
            	<span class="txt-rd">补货中</span>
            	<%if(null != vwList.getRestockDate() && vwList.getRestockDate().getTime()>System.currentTimeMillis()){%><br/>预计<%=dateFormat.format(vwList.getRestockDate())%>到货<%}%>
            <%} %>
            <br/><span class="already-remind"<%if(!"Y".equals(vwList.getIsRestockNotify())){%> style="display:none"<%}%> id="remindseted_<%=vwList.getId() %>"><b></b>已设定到货通知</span>
            </td>
            <td class="txt-price" <%if(vwList.getShelf_qty()==0){%>id="pdel_<%=i%>"<%}else{%>id="pok_<%=i%>"<%} %>><%=vwList.getShelfPrice().setScale(1)%></td>
            <td>
            <a href="javascript:;" id="cel_<%=vwList.getId() %>">删除</a><br />
            <%if(vwList.getShelfPrice()!=null && (!vwList.getIs_delete().equals("Q")) && vwList.getShelf_qty()!=0){%><a href="<%=vwList.getFullUrl()%>">立即购买</a><br /><%} %>
            <%if(vwList.getShelf_qty()<=0){%>
            	<a href="javascript:;" id="arestock_<%=vwList.getId() %>" <%if("Y".equals(vwList.getIsRestockNotify())){%>style="display:none"<%}%>>我要到货通知</a>
            <%} %>
            <a href="javascript:;" id="crestock_<%=vwList.getId() %>" <%if(!"Y".equals(vwList.getIsRestockNotify())){%>style="display:none"<%}%>>取消到货通知</a>
            </td>
          </tr>
         <% } %>
        </tbody>
      </table>
      <div class="f-lt" style="margin-bottom:-2em;"><input type="submit" id="del_button" value="删除所选" /></div>
      <p class="bg-gy" align="right" >共${productListSize}笔： <span id="pNum"></span> 
      	<c-rt:choose><c-rt:when test="${productListSize<=20}">
			<span class="a-no">&lt; 上一页</span> |  <span class="a-no">下一页 &gt;</span>
		</c-rt:when><c-rt:otherwise>
			<a href="javascript:;" class="a-togo" id="preP">上一页</a> | <a href="javascript:;" class="a-togo" id="nextP">下一页</a>
		</c-rt:otherwise></c-rt:choose>
      </p>
      <p class="page-change">第<span id="curPage">0</span>页，共<span id="totalPage">0</span>页    
      	<c-rt:choose><c-rt:when test="${productListSize<=20}">
			<span class="a-no">&lt; 上一页</span> | 
			<c-rt:choose><c-rt:when test="${productListSize==0}">0</c-rt:when><c-rt:otherwise>1</c-rt:otherwise></c-rt:choose>
			| <span class="a-no">下一页 &gt;</span>
		</c-rt:when><c-rt:otherwise>
			<a href="javascript:;" class="a-togo" id="preP">&lt; 上一页</a> | 
      		<% int tPage = cList.size()/20;
      		if(cList.size()%20!=0){
      			tPage++;
      		}
      		for(int i = 1 ; i <= tPage ; i++ ){
      			out.write("<a href=\"javascript:;\" id=\"directP_"+i+"\">"+i+"</a>");
      		}
      		%> | <a href="javascript:;" class="a-togo" id="nextP">下一页 &gt;</a>
		</c-rt:otherwise></c-rt:choose>
      </p>

    <!-- 注意事项 -->
    <div class="txt-note">
      <ul>
        <li>．已下架的商品，将自动从收藏盒中移除，不再另行通知。</li>
        <li>．收藏清单中的价格仅供参考，实际购买金额以订购资料填写页中的价格為準。</li>
      </ul>
    </div>
    <!-- 注意事项 -->

    </div>
  </div>
  <div id="pager" class="pager" style="display:none;">
	<form>
		<a href="javascript:'" id="pager_first" class="first"/>first</a>
		<a href="javascript:'" id="pager_pre" class="prev"/>pre</a>
		<input type="text" class="pagedisplay" id="pagenum"/>
		<a href="javascript:'" id="pager_next" class="next"/>next</a>
		<a href="javascript:'" id="pager_last" class="last"/>last</a>
		<select class="pagesize">
			<option selected="selected"  value="20">20</option>
		</select>
	</form>
</div>
<div id="del_dialog" title="删除商品"  class="alert-caution" style="display:none">
<p>删除商品后，原本如有设定的到货通知也将一并取消，确定要删除？</p>
<div style="text-align:center;"><a href="javascript:;" id="delete_commit" class="btn-mid">删除</a><a href="javascript:;" id="delete_cancel" class="btn-mid">取消</a></div>
</div>
<div id="mdialog" class="od-cancel-dailog" style="display:none">
<br /><p id="dialog_msg" style="text-align:center;"></p><br />
<div style="text-align:center;"><a href="javascript:;" id="msg_ok" class="btn-mid">确定</a></div></div>
<div id="m2dialog" title="删除商品"  class="alert-caution" style="display:none">
<p><br />请勾选要删除的商品！</p>
<div style="text-align:center;"><a href="javascript:;" class="btn-mid" id="m2_ok">确定</a></div>
</div>
<div id="sReminDialog" title="补货通知"  class="dailog-ok" style="display:none">
<p>设定成功！<br />货到时系统会立即以email通知您。</p>
<div style="text-align:center;"><a href="javascript:;" id="sr_ok" class="btn-mid">确定</a></div>
</div>

<div id="rcReminDialog" title="补货通知"  class="alert-caution" style="display:none">
<p><br />确定要取消到货通知？</p>
<div style="text-align:center;"><a href="javascript:;" id="rcr_ok" class="btn-mid-8">是，我确定取消</a><a href="javascript:;" id="rcr_cancel" class="btn-mid">不要取消</a></div>
</div>

</body>
</html>